from django.contrib.auth.mixins import LoginRequiredMixin

from model.models import User


class Person(LoginRequiredMixin):
    """ person user login authentication """

    def dispatch(self, request, *args, **kwargs):
        # Verify login
        user = request.user
        if not user.is_authenticated or user.role not in User.Role:
            return self.handle_no_permission()
        return super().dispatch(request, *args, **kwargs)

    def handle_no_permission(self):
        """ No login processing """
        from server.utils import Response, Code
        return Response.Json(code=Code.NotLogin)
